package com.infindo.appcreate.zzyj.util;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;


public class OneUrlConnction {

	public static OneUrlConnction oneUrlConnction = null;
	
	
	private   HttpURLConnection urlConnection= null;
	
	private OneUrlConnction() {}
	
	
	public synchronized static  OneUrlConnction getSingleOneUrlConnction( ){
		if(null == oneUrlConnction){
			oneUrlConnction = new OneUrlConnction();
		}
		return oneUrlConnction;
	}
	
	
	public  HttpURLConnection getHttpUrlConnection(String urlStr) throws Exception{
		URL url;
		HttpURLConnection urlConnection = null;
		/*try {*/
			url = new URL(urlStr);
			
			if(null == urlConnection){
				urlConnection = (HttpURLConnection)url.openConnection();
				urlConnection.setDoOutput(true);
				urlConnection.setUseCaches(true);
				urlConnection.setRequestProperty("Content-type", "application/x-java-serialized-object");
				urlConnection.setRequestMethod("POST");
				urlConnection.setUseCaches(false);
				urlConnection.setConnectTimeout(300000);  
				urlConnection.setReadTimeout(600000);
			}
			
			 /*}catch (MalformedURLException e) {
			e.printStackTrace();
		}catch (IOException e) {
			e.printStackTrace();
		}*/
		return urlConnection;
	}

	public void disconnect() {
		if(null != urlConnection){
			urlConnection.disconnect();
			urlConnection = null;
		}
	}


	public void connect() throws IOException {
		if(null != urlConnection){
			urlConnection.connect();
		}
	}
	
	
	public static void main(String[] args){
		//http://192.168.1.104:8080/appcreate/back/buildCallBack?appId=6650&result=true&pcode=Android&zipUrl=download/5/5_18_Android.zip&binaryUrl=download/5/5_18_Android.apk
	}
	
}
